<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加文章分类</title>
	<link rel="stylesheet" href="/admin/src/css/layui.css">

	<style>
		.mr10{
			display: inline-block;
		}
		.layui-form-label{
			min-width: 100px;
		}
		.layui-upload{
			margin-left: 30px;
		}
		.layui-input-block textarea{
			width:450px;
		}
		.layui-form-item .layui-input-inline{
			width:400px;
		}
	</style>
</head>

<body >
	<form class="layui-form " style="margin:20px auto;">
		<div class="layui-form-item">
			<label class="layui-form-label">文章分类名称</label>
			<div class="layui-input-inline">
				<input type="text" name="title" id="title" lay-verify="required" placeholder="请输入文章分类名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-inline">
				<input type="text" name="sort" id="sort" lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">是否显示</label>
		    <div class="layui-input-block">
				<input type="radio" name="is_status" value="1" title="是" checked>
				<input type="radio" name="is_status" value="0" title="否">
		    </div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-inline">
				<input type="text" name="remark" id="remark"  placeholder="请输入备注" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">简介</label>
			<div class="layui-input-block">
				<textarea name="info" placeholder="请输入简介" class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-upload">
			<button type="button" class="layui-btn" id="test1">选择分类图片</button>
			<div class="layui-upload-list">
				<img style="width:200px;" class="layui-upload-img" id="demo1">
				<p id="demoText"></p>
			</div>
		</div>

	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
	    </div>
	  </div>
	</form>
	<script src="/admin/src/layui.js" ></script>
<script>

    layui.use(['form','jquery','upload'], function(){
      var form = layui.form ,
		  layer = layui.layer,
          upload = layui.upload,
		  $= layui.jquery;
          var imgList = '';

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/admin/upload/images/uploadImg?imgType=articleType' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 0){
                    $("#demo1").attr('src',res.data);
                    imgList = res.data;
				}else{
                    layer.msg(res.message);
				}
            }
        });


      //监听表单提交
      form.on('submit(formDemo)', function(data){
		var getData = data.field;
		getData.image =  imgList;
		//return false;
		$.ajax({
			url: '/admin/articleType/add/data',
			type: 'POST',
			data:getData,
			success : function (backData) {
				//添加成功
			  if(backData['status'] == 200){
				  layer.msg(backData.message,{time:1200},function(){
					  window.parent.frames.location.href="/admin/articleType/index"
				  })
				  
			  }else{
				  layer.msg(backData.message);
			  }
			}
		})
        return false;
      });
    });




</script>
</body>
</html>
